package com.lzh.edu.controller;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lzh.commonutils.CommonResult;
import com.lzh.edu.client.VodClient;
import com.lzh.edu.entity.Video;
import com.lzh.edu.service.VideoService;
import com.lzh.edu.vo.VideoInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author lizuhu
 * @since 2021-04-24
 */
@CrossOrigin
@RestController
@RequestMapping("/edu/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "添加小节")
    @PostMapping("/saveVideo")
    public CommonResult saveVideo(@RequestBody Video video) {
        videoService.save(video);
        return CommonResult.ok();
    }

    @ApiOperation(value = "根据id获取小节信息")
    @GetMapping("/getVideoById")
    public CommonResult getVideoById(@RequestParam String videoId) {
       Video video =  videoService.getById(videoId);
        return CommonResult.ok().data("item",video);
    }

    @ApiOperation(value = "修改小节")
    @PutMapping("/updateVideo")
    public CommonResult updateVideoById(@RequestBody Video video) {
        videoService.updateById(video);
        return CommonResult.ok();
    }


    @ApiOperation(value = "根据课时id删除小节")
    @DeleteMapping("/deleteVideo")
    public CommonResult removeVideo(@RequestParam String videoId) {
        //删除视频资源 TODO
        boolean result = videoService.removeVideoByVideoId(videoId);
        if(result) {
            return CommonResult.ok();
        }else {
            return CommonResult.error().message("小节删除失败");
        }
    }

}

